import Vuex from 'vuex';
import Vue from "vue";

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        token: '',
        name: '',
        avatar: '',
        info: '',
        role: false,
        essays: '',
        videos: '',
        sdks: {},
        node: {},
        client: {},


    },
    mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token
        },
        SET_INFO: (state, info) => {
            state.info = info
        },
        SET_NAME: (state, name) => {
            state.name = name
        },
        SET_AVATER: (state, icon) => {
            state.avatar = icon
        },
        SET_ROLE: (state, bool) => {
            state.role = bool
        },






    },
    actions: {
        //获取用户密钥
        // Login ({ commit }, userInfo) {
        //     return new Promise((resolve, reject) => {
        //         login(userInfo).then(response => {
        //             const result = response.data;
        //             //console.log(result.token)
        //             Vue.ls.set(NAME, result.username,  60 * 60 * 1000);
        //             Vue.ls.set(TOKEN, result.token,   60 * 60 * 1000);
        //             commit('SET_TOKEN',result.token);
        //             commit('SET_NAME',result.username);
        //             resolve()
        //         }).catch(() => {
        //             reject("用户登录失败")
        //         })
        //     })
        // },
        // // 获取用户信息.用户头像
        // GetInfo ({ commit }) {
        //     return new Promise((resolve, reject) => {
        //         getInfo().then(response => {
        //             const result = response.data.results[0]
        //             //console.log(result)
        //             commit('SET_INFO',result);
        //             commit('SET_ROLE',true);
        //             commit('SET_AVATER',result.avater);
        //             //console.log(Vue.ls.get(TOKEN,''))
        //             resolve(response)
        //         }).catch(error => {
        //             commit('SET_ROLE',false);
        //             reject(error)
        //         })
        //     })
        // },




    },
    getters: {
        token: state => state.token,

    }

});
export default store;